package com.hex.liyue.messagemodule.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.hex.liyue.LiYueApplication;
import com.hex.liyue.R;
import com.hex.liyue.commonmodule.glide.GlideCircleTransform;
import com.hex.liyue.commonmodule.utils.DateUtils;
import com.hex.liyue.giftmodule.activity.DiscountDetailsActivity;
import com.hex.liyue.giftmodule.activity.HarvestDetailsActivity;
import com.hex.liyue.lookingdatemodule.activity.InSomeDetailsActivity;
import com.hex.liyue.messagemodule.bean.SystemMsgResultBean;
import com.hex.liyue.usermodule.activity.OrderDetailsActivity;
import com.hex.liyue.usermodule.activity.PersonEditActivity;
import com.hex.liyue.usermodule.activity.WalletActivity;

import java.util.List;

/**
 * Created by yukuo on 2016/5/16.
 */
public class SystemMessageListAdapter extends RecyclerView.Adapter<SystemMessageListAdapter.MyHolder> {
    private List<SystemMsgResultBean.DataBean> list;
    private Context context;

    public SystemMessageListAdapter(List<SystemMsgResultBean.DataBean> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(parent.getContext(), R.layout.item_system_msg_list, null);
        return new MyHolder(view);
    }

    @Override
    public void onBindViewHolder(final MyHolder holder, final int position) {
        //创建时间
        String time = DateUtils.getFormatDate(Long.parseLong(list.get(position).create_time) * 1000l, "yyyy-MM-dd HH:mm");
        holder.tv_item_system_msg_time.setText(time);
        //头像默认的icon
        Glide.with(LiYueApplication.getInstance()).load(R.drawable.share_icon)
                .transform(new GlideCircleTransform(LiYueApplication.getInstance()))
                .into(holder.tv_item_system_msg_avator);
        //消息内容
        if ("" != list.get(position).target_id) {
            holder.tv_item_system_msg_desc.setText(list.get(position).content);
            holder.tv_item_system_msg_desc.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (1 == Integer.parseInt(list.get(position).type)) {//约会相关
                        Intent intent = new Intent(context, InSomeDetailsActivity.class);
                        intent.putExtra("appointment_id", list.get(position).target_id);
                        context.startActivity(intent);

                    } else if (2 == Integer.parseInt(list.get(position).type)) {//提醒确认约会成功
                        Intent intent = new Intent(context, InSomeDetailsActivity.class);
                        intent.putExtra("appointment_id", list.get(position).target_id);
                        context.startActivity(intent);
                    } else if (3 == Integer.parseInt(list.get(position).type)) {//礼物折现
                        Intent intent = new Intent(context, DiscountDetailsActivity.class);
                        intent.putExtra("user_gift_cash_id", list.get(position).target_id);
                        context.startActivity(intent);
                    } else if (4 == Integer.parseInt(list.get(position).type)) {//礼物收货
                        Intent intent = new Intent(context, HarvestDetailsActivity.class);
                        intent.putExtra("user_gift_export_id", list.get(position).target_id);
                        context.startActivity(intent);
                    } else if (5 == Integer.parseInt(list.get(position).type)) {//余额提现
                        Intent intent = new Intent(context, InSomeDetailsActivity.class);
                        context.startActivity(intent);
                    } else if (6 == Integer.parseInt(list.get(position).type)) {//银行卡认证
                        Intent intent = new Intent(context, WalletActivity.class);
                        intent.putExtra("flag", false);
                        intent.putExtra("balance", 0);
                        context.startActivity(intent);
                    } else if (7 == Integer.parseInt(list.get(position).type)) {//上下线相关
                        Intent intent = new Intent(context, InSomeDetailsActivity.class);
                        context.startActivity(intent);
                    } else if (8 == Integer.parseInt(list.get(position).type)) {//订单相关
                        Intent intent = new Intent(context, OrderDetailsActivity.class);
                        intent.putExtra("orderId", list.get(position).target_id);
                        context.startActivity(intent);
                    } else if (9 == Integer.parseInt(list.get(position).type)) {//个人资料修改界面
                        Intent intent = new Intent(context, PersonEditActivity.class);
                        context.startActivity(intent);
                    } else {

                    }
                    holder.tv_item_system_msg_desc.setText(list.get(position).content);
                }
            });
        } else {
            holder.tv_item_system_msg_desc.setText(list.get(position).content);
        }

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class MyHolder extends RecyclerView.ViewHolder {
        TextView tv_item_system_msg_time;
        ImageView tv_item_system_msg_avator;
        //        TextView tv_item_system_msg_status;
        TextView tv_item_system_msg_desc;

        public MyHolder(View itemView) {
            super(itemView);
            tv_item_system_msg_time = (TextView) itemView.findViewById(R.id.tv_item_system_msg_time);
            tv_item_system_msg_avator = (ImageView) itemView.findViewById(R.id.tv_item_system_msg_avator);
//            tv_item_system_msg_status = (TextView) itemView.findViewById(R.id.tv_item_system_msg_status);
            tv_item_system_msg_desc = (TextView) itemView.findViewById(R.id.tv_item_system_msg_desc);
        }
    }
}
